<?php
include '../include/functions.php';
?>
<!DOCTYPE html PUBLIC "-//W3C//Dtd html 4.01 Transitional//EN"
"http://www.w3.org/tr/html4/loose.dtd">
<html><!-- InstanceBegin template="/Templates/MAIN.dwt.php" codeOutsideHTMLIsLocked="false" -->
  <head>
    <!-- InstanceBeginEditable name="doctitle" -->
    <title>JoshHughes.com NFL Football Pool</title>
    <!-- InstanceEndEditable -->
	<link rel="stylesheet" href="css/football.css" type="text/css">
    <script src="scripts/prototype.js" type="text/javascript"></script>
	<script src="scripts/scriptaculous.js" type="text/javascript"></script>
	<script type="text/javascript">
	// Dynamic Iframe loader
	function loadIframe(theFrame, theURL) {
		document.getElementById(theFrame).src=theURL;
	}
	
	// resizes Iframe according to content
	function resizeMe(obj){ 
	docHeight = mainContent.document.body.scrollHeight
	 obj.style.height = docHeight + 'px'
	 } 
	</script>
    <!-- InstanceBeginEditable name="head" -->
    <script language="javascript">
		function checkMail()
		{
			var x = document.registerForm.email.value;
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
			if (filter.test(x)) {
				if (document.registerForm.pass1.value == document.registerForm.pass2.value ) {
					return true;
				} else {
					alert('Passwords do not match. Please try again.');
					return false;
				}
			}
			else {
				alert('Incorrect email address');
				return false;
			}
		}
	
		<!--Combo Box Image Selector
		function showimage()
		{
		if (!document.images)
		return
		document.images.buttons.src= "../images/buttons/" +
		document.registerForm.FavTeam.options[document.registerForm.FavTeam.selectedIndex].value + ".gif"
		document.images.squares.src= "../images/squares/" +
		document.registerForm.FavTeam.options[document.registerForm.FavTeam.selectedIndex].value + ".gif"
		document.images.helmets.src= "../images/helmets/" +
		document.registerForm.FavTeam.options[document.registerForm.FavTeam.selectedIndex].value + ".gif"
		}
		//-->
	</script>

    <!-- InstanceEndEditable -->
  </head>
<body>
<div id="pagewidth" >
	<div id="header" >
	
		<?PHP include_once("layout/header.html"); ?>
		
	</div>
			<div id="wrapper" class="clearfix" > 
			<div id="maincol" >

			<!-- InstanceBeginEditable name="Contents" -->
				<?
				$pool_title = "JoshHughes.com Football Pool";
				$pool_Email = "Football@joshhughes.com";
				$pool_url = "http://football.joshhughes.com";
				$pool_folder = "/";
				$doform="0";
				if (isset($_POST['submit']))
				{
					if (strlen($_POST[username]) == 0)
					{
						echo "<h3>Please enter a Username.</h3>";
						$doform="1";
					}
					elseif (strlen($_POST[pass1]) == 0)
					{
						echo "<h3>Please enter a password.</h3>";
						$doform="1";
					}
					elseif ((strlen($_POST[email]) == 0) || (substr($_POST[email],-3) == ".ru"))
					{
						echo "<h3>Please enter a valid Email.</h3>";
						$doform="1";
					}
					elseif (strlen($_POST[Fname]) == 0)
					{
						echo "<h3>Please enter a First name.</h3>";
						$doform="1";
					}
					elseif (strlen($_POST[Lname]) == 0)
					{
						echo "<h3>Please enter a Last name.</h3>";
						$doform="1";
					}
					else
					{	//Connect To Database
						dbConnect();
						$sql="SELECT count(*) FROM Users WHERE Username='$username'";
						$count=mysql_result(mysql_query($sql),0);
						if ($count == 0)
						{
							$sql="SELECT count(*) FROM Users WHERE Email='$_POST[email]'";
							$count=mysql_result(mysql_query($sql),0);
							if ($count == 0)
							{				
								$DateJoined = date("Ymd");
								//if ($_POST["ShowEmail"]) {
								if ($ShowEmail == "yes")
								{
									$ShowEmail = false;
								}
								else
								{
									$ShowEmail = true;
								}
								if($ShowEmail)
								{
									echo "showemail<BR><BR>";
								}
								if($NFLPool == "yes") {
									$NFLPool = 1;
								} else {
									$NFLPool = 0;
								}
								
								if($AFLPool == "yes") {
									$AFLPool = 1;
								} else {
									$AFLPool = 0;
								}	
								
								//Write SQL Query to extract specified data
								$SQL = "INSERT INTO Users (Username, Password, Fname, LName, Email, DateJoined, Website, ShowEmail, FavTeam, LogoPref, RemindMe, TuesdayEmail, flag, NFL, AFL) Values ('$username', '$pass1', '$Fname', '$Lname', '$email', $DateJoined, '$website', '$ShowEmail', '$FavTeam', '$LogoPref', 1, 1, 0, $NFLPool, $AFLPool)";
								//Open Record Set using SQL Query
								if (mysql_query($SQL))
								{
									//********************************************
									//Send an Email to me notifying User to activate account of a request
									$id=md5($email);
									$to = "$_POST[Fname] $_POST[Lname] <$_POST[email]>";
									$headers = "From: $pool_title <$pool_Email>\n";
									$subject = "Your $pool_title Account";
									$message = "Hi $_POST[Fname]\n\nThank you for registering with the $pool_title.\n\nTo complete your registration we ask you to confirm your e-mail address.\n\nTo do this, simply click the following link:\n".$pool_url."/activate.php?id=$id\n\nIf you need any help, just reply to this Email.\n\n\n$pool_title";
									//message send
									mail($to, $subject, $message, $headers);
									//********************************************
									
									//********************************************
									//Send an Email to me notifying me of a request
									$MailTo = "<Football@joshhughes.com>";
									$MailFrom = "From: Football@joshhughes.com";
									$MailSubject = "A new user just signed up";
									$MailBody = "At ".date('g:i A',time())."\nUsername = $username\nPassword = $pass1\nName = $Fname $Lname\nEmail = $email\nWebSite = $website\nFavorite Team = $FavTeam\nLogo Preference = $LogoPref";
									//message send
									mail($MailTo, $MailSubject, $MailBody, $MailFrom);					
									//********************************************
									echo "<h3>Thank you for registering.</h3><p>You now need to activate your account by clicking the link in an e-mail which has been sent to you at <b>$_POST[email]</b>.</p>\n";
									echo "You have been registerd with the following information:<BR><BR>";
									echo "Username = <I>$username</I><BR>Password = <I>$pass1</I><BR>Name = <i>$Fname $Lname</I><BR>Email = <I>$email</I> ";
									if ($ShowEmail = 0)
									{
										echo "(Kept Private)";
									}
									echo "<BR>WebSite = <I>$website</I><BR>Favorite Team = <I>$FavTeam</I><BR>Logo Preference = <I>$LogoPref</I><BR><BR><a href=\"members.php\" class=\"permLink\">Click Here to View Members Directory</a>";
								}
								else
								{
									echo "<h3>There has been an error processing your request.</h3><p>Please try again.\n";
									$doform="1";
								}
							}
							else
							{
								echo "	<h3>The Email address <b>$_POST[Email]</b> already exists, please enter another.</h3>";
								$doform="1";
							}
						}
						else
						{
							echo "<h3>The Username <b>$Username</b> already exists, please enter another.</h3>";
							$doform="1";
						}
					}
				}
				else
				{
				  $doform="1";
				}
				
				if ($doform == '1')
				{
				?>
				<table width="500" cellpadding="5" cellspacing="0">
					<tr>
					<td class="redbg" align="Left"><span class="whitelink">Register For The Pool</span></td>
					</tr>
					<td class="redbg" align="Left">
						<form name="registerForm" action="<?PHP echo $PHP_SELF; ?>" method="POST" onsubmit="return checkMail(this)">
						<table width="500" border="0" cellspacing="3" cellpadding="3" border="0" bgcolor="#FFFFFF">
							<tr> 
							  <td height="75"><p align="left">
							  <h3>Fill in the following information:</h3>
							  <ul>
								<li>Required fields marked with a red asterisk.</li>
								<li>You must use a valid e-mail address, it is needed to confirm your account.  Your email is also used to notify you of upcoming games that you may need to make picks for, and to inform you of updates to the pool.</li>
								<li>Check the &quot;Make Private&quot; box under Email if you wish to keep others from viewing your email address.</li>
								<li>Usernames <B>DO NOT</B> have to be a form of your real name, however vulgar or derogatory usernames will be removed.  You will be able to change your username, as you wish.</li>
							  </ul>
								  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="style1">
									<tr> 
									  <td width="115" height="25"><font color="#FF0000">*</font>First Name:</td>
									  <td height="25"><input name="Fname" type="text" id="Fname" value="<?=$_POST[Fname]?>" size="35"></td>
									</tr>
									<tr> 
									  <td width="115" height="25"><font color="#FF0000">*</font>Last Name:</td>
									  <td height="25"><input name="Lname" type="text" id="Lname" value="<?=$_POST[Lname]?>" size="35"></td>
									</tr>
									<tr> 
									  <td width="115" height="25"><font color="#FF0000">*</font>Username:</td>
									  <td height="25"><input name="username" type="text" id="username" value="<?=$_POST[username]?>" size="35"></td>
									</tr>
									<tr> 
									  <td width="115" height="25"><font color="#FF0000">*</font>Password:</td>
									  <td height="25"><input name="pass1" type="password" id="pass1" size="35"></td>
									</tr>
									<tr> 
									  <td width="115" height="25"><font color="#FF0000">*</font>Confirm:</td>
									  <td height="25"><input name="pass2" type="password" id="pass2" size="35"></td>
									</tr>
									<tr> 
									  <td width="115" height="25"><font color="#FF0000">*</font>E-mail 
										Address:</td>
									  <td height="25"><input name="email" type="text" id="email" value="<?=$_POST[email]?>" size="35"></td>
									</tr>
									<tr> 
									  <td height="25" colspan="2"><blockquote>Make Private: <input name="ShowEmail" type="Checkbox" id="ShowEmail" value="yes"></blockquote></td>
									</tr>
									<tr> 
									  <td width="115" height="25">Website:</td>
									  <td height="25"><input name="website" type="text" id="website" value="http://" size="35"></td>
									</tr>
									<tr> 
									  <td width="115" height="25">Play NFL Pool:</td>
									  <td height="25"><input name="NFLPool" type="Checkbox" id="NFLPool" value="yes" checked></td>
									</tr>
									<tr> 
									  <td width="115" height="25">Play AFL Pool:</td>
									  <td height="25"><input name="AFLPool" type="Checkbox" id="AFLPool" value="yes"></td>
									</tr>
									<tr> 
									  <td width="115" height="25">Favorite (NFL) Team:</td>
									  <td height="25"><select class="select" name="FavTeam" id="FavTeam" onChange="showimage()"><option selected>Select One</option>
										<?php
										//Connect To Database
										dbConnect();
										//Write SQL Query to extract specified data
										$SQL = "SELECT TeamName FROM NFLTeams ORDER BY TeamName";
										//Open Record Set using SQL Query
										$result = mysql_query($SQL) or die("Cannot query the database.<br/>");
										do
										{
											if ($myrow["TeamName"] != "")
											{
											echo "<option value=\"".$myrow["TeamName"]."\">".$myrow["TeamName"]."</option>";
											}
										}while($myrow = mysql_fetch_array($result));
										?>
										</select>
										</td>
									</tr>
									<tr> 
									  <td width="115" height="25" valign="top">Logo Preference:</td><td>&nbsp;</td>
									</tr>
									<tr>
									  <td height="25" colspan="2">
										<table>
										   <tr>
											<td valign="Bottom" width="33%"><input type="radio" name="LogoPref" id="LogoPref" value="buttons">Round Logo</td>
											<td valign="Bottom" width="33%"><input type="radio" name="LogoPref" id="LogoPref" value="squares">Square Logo</td>
											<td valign="Bottom" width="34%"><input type="radio" name="LogoPref" id="LogoPref" value="helmets">Helmet Logo</td>
								
										   </tr>
										   <tr>
											<td valign="middle"><img src="../images/buttons/blank.gif" name="buttons" ></td>
											<td valign="middle"><img src="../images/squares/blank.gif" name="squares" ></td>
											<td valign="middle"><img src="../images/helmets/blank.gif" name="helmets" ></td>
										   </tr>
										</table>
									  </td>
									</tr>
									<tr> 
									  <td height="25" colspan="2"><div align="center"> 
										  <input type="submit" name="submit" value="Submit">
										  <input type="reset" name="Submit2" value="Reset">
										  &nbsp;&nbsp;&nbsp;</div></td>
									</tr>
								  </table>
								</form>
								</td>
							</tr>
							</table>
					</td>
					</tr>
					</table>
				<?						
				}
				?>

			<!-- InstanceEndEditable -->
			
			</div>
			<div id="leftcol" >
			
				<?PHP include_once("layout/left_column.php"); ?>
		
			</div>
			
		</div>
		
		<div id="footer" >
		
			<?PHP include_once("layout/footer.html"); ?>
			
		</div>
</div>
</body>
<!-- InstanceEnd --></html>